
#include "../common.h"

void file_stat(char *file)
{
	struct stat buf;
	if (-1 == stat(file, &buf))
	{
		printf("stat failed \n");
		exit(-1);
	}

	printf("st_size=[%d]\n", buf.st_size);
	printf("st_ctime=[%s]\n", ctime(&buf.st_ctime));
	printf("st_mtime=[%s]\n", ctime(&buf.st_mtime));

	if(S_ISUID & buf.st_mode) printf("suid is set\n");
	if(S_ISGID & buf.st_mode) printf("sgid is set\n");
	
	return;
}

int main(int argc, char** argv)
{
	file_stat(argv[1]);
	if (-1 == truncate(argv[1], 5))
	{
		printf("truncate failed \n");
		return -1;
	}

	printf("after truncate--------\n");
	file_stat(argv[1]);

	return 0;
}
